<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>ODBC and DB2 Functions (PDO_ODBC)</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.pdo-oci.connection.html">« PDO_OCI DSN</a></li>
      <li style="float: right;"><a href="ref.pdo-odbc.connection.html">PDO_ODBC DSN »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="pdo.drivers.html">PDO 驱动</a></li>
    <li>ODBC and DB2 Functions (PDO_ODBC)</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ref.pdo-odbc" class="reference">
  
  <h1 class="title">ODBC and DB2 Functions (PDO_ODBC)</h1>
  
  <div class="partintro">

   <div class="section" id="pdo-odbc.intro">
   <h2 class="title">简介</h2>
    <p class="para">
     PDO_ODBC is a driver that implements the <a href="intro.pdo.html" class="link">PHP Data
     Objects (PDO) interface</a>
     to enable access from PHP to databases through ODBC drivers or through the
     IBM DB2 Call Level Interface (DB2 CLI) library. PDO_ODBC currently supports
     three different &quot;flavours&quot; of database drivers:
     <dl>
      
       <dt>
ibm-db2</dt>

       <dd>

        <p class="para">
         Supports access to IBM DB2 Universal Database, Cloudscape, and Apache
         Derby servers through the free DB2 express-C client.
        </p>
       </dd>

      
      
       <dt>
unixODBC</dt>

       <dd>

        <p class="para">
         Supports access to database servers through the unixODBC driver
         manager and the database&#039;s own ODBC drivers. 
        </p>
       </dd>

      
      
       <dt>
generic</dt>

       <dd>

        <p class="para">
         Offers a compile option for ODBC driver managers that are not
         explicitly supported by PDO_ODBC.
        </p>
       </dd>

      
     </dl>

    </p>
    <p class="para">
     On Windows, <var class="filename">php_pdo_odbc.dll</var> has to be enabled as
     extension in <var class="filename">php.ini</var>. It is linked
     against the Windows ODBC Driver Manager so that PHP can connect to any
     database cataloged as a System DSN.
    </p>
   </div>

   
   

<div class="section" id="ref.pdo-odbc.installation">
 <h2 class="title">安装</h2>
 <div class="procedure">
  <strong class="title">PDO_ODBC on UNIX systems</strong>
  <ol type="1"><li>
   <p class="para">
    PDO_ODBC is included in the PHP source. You can compile the
    PDO_ODBC extension as either a static or shared module using the following
    <strong class="command">configure</strong> commands.
    <dl>
     
      <dt>
ibm_db2</dt>

      <dd>

       <p class="para">
        <div class="example-contents screen"><div class="cdata"><pre>
./configure --with-pdo-odbc=ibm-db2,/opt/IBM/db2/V8.1/
</pre></div></div>
        To build PDO_ODBC with the ibm-db2 flavour, you have to have
        previously installed the DB2 application development headers on the
        same machine on which you are compiling PDO_ODBC. The DB2 application
        development headers are an installable option in the DB2 servers, and
        are also available as part of the DB2 Application Development Client
        freely available for download from the IBM developerWorks 
        <a href="https://www.ibm.com/developerworks/downloads/im/db2express/index.html" class="link external">&raquo;&nbsp;website</a>.
       </p>
       <p class="para">
        If you do not supply a location for the DB2 libraries and headers to
        the <strong class="command">configure</strong> command, PDO_ODBC defaults to
        <var class="filename">/home/db2inst1/sqllib</var>.
       </p>
      </dd>

     
     
      <dt>
unixODBC</dt>

      <dd>

       <p class="para">
        <div class="example-contents screen"><div class="cdata"><pre>
./configure --with-pdo-odbc=unixODBC,/usr/local
</pre></div></div>
        If you do not supply a location for the unixODBC libraries and
        headers to the <strong class="command">configure</strong> command, PDO_ODBC
        defaults to <var class="filename">/usr/local</var>.
       </p>
      </dd>

     
     
      <dt>
generic</dt>

      <dd>

       <div class="example-contents screen"><div class="cdata"><pre>
./configure --with-pdo-odbc=generic,/usr/local,libname,ldflags,cflags
</pre></div></div>
      </dd>

     
    </dl>

   </p>
  </li>
 </ol></div>
</div>



   
   


<div class="section" id="pdo-odbc.constants">
 <h2 class="title">预定义常量</h2>
 <p class="simpara">下列常量由此驱动定义，且仅在扩展编译入 PHP
或在运行时动态载入时可用。另外，使用此驱动时，仅会使用这些驱动特定的常量。使用其他驱动的驱动特定的常量可能会导致不可预见的情况。如果代码可运行于多个驱动，<span class="function"><a href="pdo.getattribute.html" class="function">PDO::getAttribute()</a></span>
可被用于获取
<strong><code>PDO_ATTR_DRIVER_NAME</code></strong>
属性以检查驱动。</p>
 <dl>
  
   <dt id="pdo.constants.odbc-attr-use-cursor-library">
    <strong><code>PDO::ODBC_ATTR_USE_CURSOR_LIBRARY</code></strong>
     (<span class="type">int</span>)
   </dt>

   <dd>

    <p class="para">
     This option controls whether the ODBC cursor library is used. The ODBC cursor library
     supports some advanced ODBC features (e.g. block scrollable cursors), which may not
     be implemented by the driver. The following values are supported:
     <ul class="itemizedlist">
      <li class="listitem">
       <p class="para">
        <strong><code>PDO::ODBC_SQL_USE_IF_NEEDED</code></strong> (the default):
        use the ODBC cursor library when needed.
       </p>
      </li>
      <li class="listitem">
       <p class="para">
        <strong><code>PDO::ODBC_SQL_USE_DRIVER</code></strong>:
        never use the ODBC cursor library.
       </p>
      </li>
      <li class="listitem">
       <p class="para">
        <strong><code>PDO::ODBC_SQL_USE_ODBC</code></strong>:
        always use the ODBC cursor library.
       </p>
      </li>
     </ul>
    </p>
   </dd>

  
  
   <dt id="pdo.constants.odbc-attr-assume-utf8">
    <strong><code>PDO::ODBC_ATTR_ASSUME_UTF8</code></strong>
     (<span class="type">bool</span>)
   </dt>

   <dd>

    <p class="para">
     Windows only. If <strong><code>true</code></strong>, UTF-16 encoded character data (<code class="literal">CHAR</code>,
     <code class="literal">VARCHAR</code> and <code class="literal">LONGVARCHAR</code>) is converted to
     UTF-8 when reading from or writing data to the database.
     If <strong><code>false</code></strong> (the default), character encoding conversion may be done by the driver.
    </p>
   </dd>

  
 </dl>

</div>



   
   

<div class="section" id="pdo-odbc.configuration">
 <h2 class="title">运行时配置</h2>
 <p class="simpara">
这些函数的行为受 <var class="filename">php.ini</var> 中的设置影响。
</p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>PDO_ODBC Configuration Options</strong></caption>
   
    <thead>
     <tr>
      <th>名字</th>
      <th>默认</th>
      <th>可修改范围</th>
      <th>更新日志</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><a href="ref.pdo-odbc.html#ini.pdo-odbc.connection-pooling" class="link">pdo_odbc.connection_pooling</a></td>
      <td>&quot;strict&quot;</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="ref.pdo-odbc.html#ini.pdo-odbc.db2-instance-name" class="link">pdo_odbc.db2_instance_name</a></td>
      <td>NULL</td>
      <td>PHP_INI_SYSTEM</td>
      <td>本过时特性<em class="emphasis">将</em>肯定会在未来被<em class="emphasis">移除</em>。</td>
     </tr>

    </tbody>
   
  </table>

  有关 PHP_INI_* 样式的更多详情与定义，见 <a href="configuration.changes.modes.html" class="xref">配置可被设定范围</a>。
</p>

<p class="para">这是配置指令的简短说明。</p>

<p class="para">
 <dl>
   
   <dt id="ini.pdo-odbc.connection-pooling">
    <code class="parameter">pdo_odbc.connection_pooling</code>
    <span class="type">string</span>
   </dt>

   <dd>

    <p class="para">
     Whether to pool ODBC connections. Can be one of <code class="literal">&quot;strict&quot;</code>,
     <code class="literal">&quot;relaxed&quot;</code> or <code class="literal">&quot;off&quot;</code> (equals to
     <code class="literal">&quot;&quot;</code>). The parameter describes how strict the connection
     manager should be when matching connection parameters to existing pooled
     connections.  <strong class="userinput"><code>strict</code></strong> is the recommend default, and
     will result in the use of cached connections only when all the connection
     parameters match exactly.  <strong class="userinput"><code>relaxed</code></strong> will result in
     the use of cached connections when similar connection parameters are
     used.  This can result in increased use of the cache, at the risk of
     bleeding connection information between (for example) virtual hosts.
    </p>
    <p class="para">
     This setting can only be changed from the <var class="filename">php.ini</var>
     file, and affects the entire process; any other modules loaded into the
     process that use the same ODBC libraries will be affected too, including
     the <a href="ref.uodbc.html" class="link">Unified ODBC extension</a>.
    </p>
    <div class="warning"><strong class="warning">警告</strong>
     <p class="para">
      <strong class="userinput"><code>relaxed</code></strong> matching should not be used on a shared
      server, for security reasons.
     </p>
    </div>
    <div class="tip"><strong class="tip">小技巧</strong>
     <p class="para">
      Leave this setting at the default <strong class="userinput"><code>strict</code></strong> setting
      unless you have good reason to change it.
     </p>
    </div>
   </dd>

  
  
   <dt id="ini.pdo-odbc.db2-instance-name">
    <code class="parameter">pdo_odbc.db2_instance_name</code>
    <span class="type">string</span>
   </dt>

   <dd>

    <p class="para">
     If you compile PDO_ODBC using the <code class="literal">db2</code> flavour,
     this setting sets the value of the DB2INSTANCE environment variable on
     Linux and UNIX operating systems to the specified name of the DB2
     instance. This enables PDO_ODBC to resolve the location of the DB2
     libraries and make cataloged connections to DB2 databases.
    </p>
    <p class="para">
     This setting can only be changed from the <var class="filename">php.ini</var>
     file, and affects the entire process; any other modules loaded into the
     process that use the same ODBC libraries will be affected too, including
     the <a href="ref.uodbc.html" class="link">Unified ODBC extension</a>.
    </p>
    <p class="para">
     This setting has no effect on Windows.
    </p>
   </dd>

  
  
 </dl>

 </p>
</div>



  </div>

  

 <h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="ref.pdo-odbc.connection.html">PDO_ODBC DSN</a> — Connecting to ODBC or DB2 databases</li></ul>
</div>
</div></div></body></html>